package com.gid.rcflightlogger;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class BatterySelectListAdapter extends ArrayAdapter<Battery> {

	private LayoutInflater mLayoutInflater;

	//constructor
	public BatterySelectListAdapter(Context context, List<Battery> items) {
		super(context, 0, items);
		mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// Notes from exampple: to get check if this item is checked
		// final ListView lv = (ListView) parent;
		// final boolean isChecked = lv.isItemChecked(position);

		final Battery item = getItem(position);
		View v = convertView;
		if (v == null) {
			v = mLayoutInflater.inflate(R.layout.layout_batteryselectoritem, null);
		}

		final TextView tagView = (TextView) v.findViewById(R.id.checkablelistItemTag);
		if (tagView != null) {
			tagView.setText(item.getTag());
		}

		final TextView nameView = (TextView) v.findViewById(R.id.checkablelistItemName);
		if (nameView != null) {
			nameView.setText(item.getName());
		}
		return v;
	}

	@Override
	public long getItemId(int position) {
		return getItem(position).getId();
	}

	@Override
	public boolean hasStableIds() {
		return true;
	}
}
